package com.yuanduo_app.widget

import com.facebook.react.bridge.ReadableArray
import com.facebook.react.uimanager.SimpleViewManager
import com.facebook.react.uimanager.ThemedReactContext
import com.facebook.react.uimanager.annotations.ReactProp
import com.xujl.fastlib.utils.AppManager
import com.xujl.fastlib.utils.ToastUtils
import java.util.*

/**
 * versions:
 * coding by pmj on 2021/7/26
 * desc:
 */
class WaterCameraViewManager : SimpleViewManager<WaterCameraView>() {
    val onPause = 1;
    val onResume = 2;
    val onDestroy = 0;
    //接收车牌号
    val receiveCarNum = 3;
    //接收备注
    val receiveRemark = 4;


    lateinit var waterCameraView: WaterCameraView
    override fun getName(): String {
        return "WaterCameraView"
    }

    override fun createViewInstance(reactContext: ThemedReactContext): WaterCameraView {
        waterCameraView = WaterCameraView(AppManager.getAppManager().currentActivity())
        return waterCameraView
    }

    override fun getCommandsMap(): Map<String, Int>? {
        val map: MutableMap<String, Int> = HashMap()
        map["onPause"] = onPause
        map["onResume"] = onResume
        map["onDestroy"] = onDestroy
        map["receiveCarNum"] = receiveCarNum
        map["receiveRemark"] = receiveRemark
        return map
    }

//    @ReactProp(name="receiveCarNum")
//    fun receiveCarNum(waterCameraView: WaterCameraView,carNum:String,lat:String,lng:String){
//        waterCameraView.setCarNum(carNum,lat,lng)
//    }
//
//
//    @ReactProp(name="receiveRemark")
//    fun receiveRemark(waterCameraView: WaterCameraView,remark:String){
//        waterCameraView.setRemark(remark)
//    }




    override fun receiveCommand(
        waterCameraView: WaterCameraView,
        commandId: Int,
        args: ReadableArray?
    ) {
        super.receiveCommand(waterCameraView, commandId, args)
        when (commandId) {
            onPause -> {
                waterCameraView.onPause()
            }
            onResume -> {
                waterCameraView.onResume()
            }
            receiveCarNum -> {
                args?.getString(0)?.let { waterCameraView.setCarNum(it) }
//                waterCameraView.onPause()
            }

            receiveRemark -> {
                ToastUtils.toast("接收数据是"+args?.getString(0)+"---"+args?.toString())

//                waterCameraView.onPause()
            }
            onDestroy -> {
                waterCameraView.onDestroy()
            }
        }

    }


}